<?php
  function Poker_API($url,$params,$assoc)
  {
    $curl = curl_init($url);
    curl_setopt($curl,CURLOPT_POST,true);
    curl_setopt($curl,CURLOPT_POSTFIELDS,$params);
    curl_setopt($curl,CURLOPT_TIMEOUT,30);
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); 
    $response = trim(curl_exec($curl));
    curl_close($curl);
    $api = Array();
    if ($assoc)  // associative array result
    {
      if (empty($response))
      {
        $api["Result"] = "Error";
        $api["Error"] = "Connection failed";
      }
      else  
      {
        $paramlist = Explode("\r\n",$response);
        
        foreach ($paramlist as $param)
        {
          $namevalue = Explode("=",$param,2);
          
          $api[$namevalue[0]] = $namevalue[1];
        }
      }
    }
    else  // regular array result
    {
      if (empty($response))
      {
        $api[] = "Result=Error"; 
        $api[] = "Error=Connection failed"; 
      }
      else  
      {
        $paramlist = Explode("\r\n",$response);
        foreach ($paramlist as $param) $api[] = $param;
      }
    }
    return $api;
  }
?>